package com.hfut.eeg.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
* @Description: 通用网络环境配置
* @author 梁琦
* @date 2019-12-30 20:06
* @throws
*/
@Configuration
public class GlobalCorsConfig {
    @Bean
    public CorsFilter corsFilter()
    {
        UrlBasedCorsConfigurationSource source  = new UrlBasedCorsConfigurationSource();
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedOrigin("*");//允许所有
        configuration.addAllowedHeader("*");//允许所有消息头
        configuration.addAllowedMethod("*");//允许所有传输方法
        configuration.setAllowCredentials(true);//需要认证
        source.registerCorsConfiguration("/**",configuration);
        return new CorsFilter(source);
    }
}
